<template>
  <div>
    <el-dialog title="新增/编辑员工" :visible.sync="addprodCatevis" @close="close" width="500px" append-to-body>
        <el-form :rules="rules" :model="adduserForm" ref="adduserForm">

            <el-form-item label="账号:" prop="username" :label-width="formLabelWidth">
                <el-input v-model="adduserForm.username"></el-input>
            </el-form-item>
            <el-form-item label="密码:" prop="password" :label-width="formLabelWidth">
                <el-input type="password" v-model="adduserForm.password"></el-input>
            </el-form-item>
            
            <el-form-item label="创建日期:" :label-width="formLabelWidth">
                <el-date-picker type="date" placeholder="选择日期" v-model="adduserForm.userDate" style="width: 100%;"></el-date-picker>
            </el-form-item>
            <el-form-item label="备注:" :label-width="formLabelWidth">
                <el-input v-model="adduserForm.userRemark" placeholder=""></el-input>
            </el-form-item>

        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="close">取 消</el-button>
          <el-button type="danger" :loading="submitLoading" @click="submitProdCategory('adduserForm')">确 定</el-button>
        </div>
          </el-dialog>
        </div>
</template>

<script>
import { AddProdCate, EditProdCate } from '@/api/prod';
export default {
  name: 'addprodcate',
  props: ['adduserDialog', 'checkCategory', 'addTwoId'],
  data() {
    return {
      addprodCatevis: false,
      submitLoading: false,
      adduserForm: {
        username: '',
        password: '',
        userRemark: '',
        userDate: new Date()
      },
      formLabelWidth: '90px',
      rules: {
          username: [
            { required: true, message: '请输入账号', trigger: 'blur' },
          ],
          password: [
            { required: true, message: '请输入密码', trigger: 'blur' },
          ],
      }
    }
  },
  methods: {
    close() {
      this.addprodCatevis = false;
      this.resetForm();
      this.$emit("update:adduserDialog", false);
    },
    resetForm() {
      this.adduserForm.username = '';
      this.adduserForm.password = '';
      this.adduserForm.userRemark = '';
      this.adduserForm.userDate = new Date();
    },
    submitProdCategory(formName) {
        // this.$refs[formName].validate((valid) => {
        //     if (valid) {
        //       if (!this.addTwoId) {
        //         // 如果没有传入分类Id，则就是添加一级分类
        //         if (this.checkCategory) {
        //           // 修改类别
        //           let reqData = {
        //               categoryId: this.checkCategory.categoryId,
        //               username: this.adduserForm.username,
        //               password: this.adduserForm.password,
        //               userRemark: this.adduserForm.userRemark,
        //               userDate: this.adduserForm.userDate
        //           }
        //           EditProdCate(reqData).then(response => {
        //               let data = response.data
        //               this.$message({
        //                   message: data.msg,
        //                   type: 'success'
        //               })
        //               this.submitLoading = false;
        //               this.$refs.adduserForm.resetFields();
        //               this.resetForm();
        //               this.addprodCatevis = false;
        //               this.$emit("update:adduserDialog", false);
        //           }).catch(error => {
        //               this.submitLoading = false;
        //           })

        //         } else {
        //           // 新增类别
        //           let reqData = {
        //               username: this.adduserForm.username,
        //               password: this.adduserForm.password,
        //               userRemark: this.adduserForm.userRemark,
        //               userDate: this.adduserForm.userDate
        //           }
        //           this.submitLoading = true;
        //           AddProdCate(reqData).then(response => {
        //               let data = response.data
        //               this.$message({
        //                   message: data.msg,
        //                   type: 'success'
        //               })
        //               this.submitLoading = false;
        //               this.$refs.adduserForm.resetFields();
        //               this.resetForm();
        //               this.addprodCatevis = false;
        //               this.$emit("update:adduserDialog", false);
        //           }).catch(error => {
        //               this.submitLoading = false;
        //           })
        //         }
        //       }
              
        //     } else {
        //       console.log('error submit!!');
        //       return false;
        //     }
        // });
    }
  },
  watch: {
    adduserDialog(newVal,oldVal) {  
      this.addprodCatevis = newVal;
    },
    checkCategory(newVal) {
      if (newVal) {
        this.adduserForm.username = newVal.username;
        this.adduserForm.password = newVal.password;
        this.adduserForm.userDate = newVal.userDate;
        this.adduserForm.userRemark = newVal.userRemark;
      }
    },
  }
}
</script>

<style lang="scss" scoped>
  
</style>